package com.gzs.zhdj.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gzs.zhdj.domain.dto.AnswerDto;
import com.gzs.zhdj.domain.dto.PageBean;
import com.gzs.zhdj.domain.dto.QAPageDto;
import com.gzs.zhdj.domain.dto.QuestionDto;
import com.gzs.zhdj.domain.entity.PartyMember;
import com.gzs.zhdj.mapper.QAMapper;
import com.gzs.zhdj.service.QAService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QAServiceImpl implements QAService {

    @Autowired
    private QAMapper qaMapper;
    @Override
    public void quest(QuestionDto questionDto) {
        qaMapper.quest(questionDto);
    }

    @Override
    public void answer(AnswerDto answerDto) {
        qaMapper.Answer(answerDto);
        qaMapper.updateStatus(answerDto.getId());
    }

    @Override
    public PageBean getQuest(QAPageDto qaPageDto) {
        PageHelper.startPage(qaPageDto.getPage(), qaPageDto.getPageSize());

        Page<PartyMember> page = qaMapper.pageQuery(qaPageDto);

        long total = page.getTotal();
        List<PartyMember> records = page.getResult();

        return new PageBean(total, records);
    }
}
